<?php
namespace app\index\controller;
use catetree\Catetree;
class Index extends Base
{
    public function index()
    {
      
         // dump($this->configs);die;

        //获取首页轮播图
        if(cache('alternateImgs')){
            $alternateImgs=cache('alternateImgs');

        }else{
            $alternateImgs=db('tp_alternate_img')->limit(3)->order('sort DESC')->select();
            if($this->configs['cache_button']=='是'){
                cache('alternateImgs', $alternateImgs, $this->configs['cache_time']);//设置缓存

            }
            

        }
        

        // dump($alternateImgs);die;
        

        //获取首页公告和促销分类的文章
       
        if(cache('annemtRes')){
            $annemtRes=cache('annemtRes');

        }else{
            $annemtRes=model('TpArticle')->getCateArts(24,3);//公告
            if($this->configs['cache_button']=='是'){
                cache('annemtRes', $annemtRes,$this->configs['cache_time']);//设置缓存

            }
          

        }
        if(cache('saleRes')){
            $saleRes=cache('saleRes');

        }else{
            $saleRes=model('TpArticle')->getCateArts(25,3);//促销
            if($this->configs['cache_button']=='是'){
                cache('saleRes', $saleRes, $this->configs['cache_time']);//设置缓存

            }
         

        }
     

        //获取首页推荐大模块的所有一级分类
        if(cache('CategoryRecpos')){
            $CategoryRecpos=cache('CategoryRecpos');
        }else{

            $CategoryRecpos=model('TpCategory')->getCateRecpos(5);
        foreach ($CategoryRecpos as $k => $v) {
            $CategoryRecpos[$k]['children']=model('TpCategory')->getCateRecpos(5,$v['id']);
            foreach ($CategoryRecpos[$k]['children'] as $k1 => $v1) {
                
                //首页推荐二级分类下所有的精品推荐商品的信息
                $bestRecposGoods=model('TpGoods')->getIndexRecposGoods($v1['id'],7);
                $CategoryRecpos[$k]['children'][$k1]['bestRecposGoods']=$bestRecposGoods;
            }
            
            //首页推荐一级分类下所有新品推荐商品的信息
            $newRecposGoods=model('TpGoods')->getIndexRecposGoods($v['id'],4);
            $CategoryRecpos[$k]['newRecposGoods']=$newRecposGoods;
            
            //首页推荐一级分类关联的品牌信息
            $data=model('TpCategory')->getCatesBrands($v['id']);
            $CategoryRecpos[$k]['brands']=$data['brands_id'];

            //首页推荐一级分类下所有关联广告信息
            $CategoryRecpos[$k]['CategoryAd']=model('TpCategory')->getCateAd($v['id']);

        }
        if($this->configs['cache_button']=='是'){
                cache('CategoryRecpos',$CategoryRecpos,$this->configs['cache_time']);//设置缓存

            }
    


        }
    	
        //获取首页推荐商品的信息
        $indexGoodsRecpos=model('TpGoods')->getGoodsRecpos(8);
    	// dump($indexGoodsRecpos);die;
        

       

    	$this->assign([
    		
    		'show_nav'=>1,//首页导航默认展开，其他页面默认收缩
    		'CategoryRecpos'=>$CategoryRecpos,
            'indexGoodsRecpos'=>$indexGoodsRecpos,
            'annemtRes'=>$annemtRes,
            'saleRes'=>$saleRes,
            'alternateImgs'=>$alternateImgs
    		
    		]);
        return view();
    }
}
